package com.zhouyx.userservice.service;

import com.zhouyx.userservice.entity.MailConfigProperties;
import com.zhouyx.userservice.entity.User;
import com.zhouyx.userservice.mapper.UserMapper;
import com.zhouyx.userservice.service.interfaces.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @title: UserServiceImp
 * @Author: max.zhou1
 * @Date: 2024/9/2 22:30
 * @Version: 1.0
 **/
//@Service
@Component
@ConditionalOnProperty(name = "serviceControl",havingValue = "userServiceImp")
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private MailConfigProperties mailConfigProperties;

    @Value("#{${host.mapping:{}}}")
    private Map<String, String> hostMap;


    @Override
    public List<User> list() {
        System.out.println("Call userMapper.list...");
        System.out.println(mailConfigProperties.getHostname());
        System.out.println(hostMap.entrySet());
        return userMapper.list();
    }

    @Override
    public Integer add(User user) {
        System.out.println("Call userMapper.add...");
        return userMapper.add(user);
    }

    @Override
    public Integer update(User user) {
        System.out.println("Call userMapper.update...");
        return userMapper.update(user);
    }

    @Override
    public Integer deleteById(Long id) {
        System.out.println("Call userMapper.deleteById...");
        return userMapper.deleteById(id);
    }


    @Override
    public User getById(Long id) {
        System.out.println("Call userMapper.getById...");
        return userMapper.getById(id);
    }
}

